How to do it?:
Open the Rmarkdown file of this assignment (link) in Rstudio.
Right under each question, insert a code chunk
(you can use the hotkey Ctrl + Alt + I to add a code chunk)
and code the solution for the question.
Knit the rmarkdown file (hotkey:
Ctrl + Alt + K) to export an html.
Publish the html file to your Githiub Page.
Submission: Submit the link on Github of the assignment to Canvas
library(tidyverse)
library(gganimate)
library(gifski)
df <- read.csv("adult_census.csv")
gganimate and gifski
then restart Rstudio. Using the Adult Census Income data,
make an animation using geom_point and
transition_states.df %>% ggplot(aes(x = hours.per.week,
y = age, color=race))+
geom_point()+
transition_states(sex)+
labs(title = 'sex: {closest_state}')
Adult Census Income data, make an animation
using geom_bar and transition_states.df %>% ggplot(aes(x = hours.per.week,
y = age, color=marital.status))+
geom_point()+
transition_states(sex)+
labs(title = 'sex: {closest_state}')
library(gapminder)
library(gganimate)
library(ggplot2)
library(tidyverse)
library(lubridate)
library(knitr)
df <- read_csv("WHO-COVID-19-global-data.csv")
df$week <- week(df$Date_reported)
d1 <- df %>% group_by(week, Country) %>% summarise(mean = mean(New_cases))
d2 <- d1 %>% group_by(week) %>% mutate(rank=rank(-mean))
d3 <- d2 %>% filter(rank <= 10)
a1 <- d3 %>% ggplot(aes(x=rank, y=mean, group=Country, fill=Country, label=Country)) + geom_col()+geom_text(aes(y = mean, label = Country), hjust = 1.4)+
coord_flip(clip = "off", expand = FALSE) +scale_x_reverse()+
labs(title = 'Week {closest_state}', x='', y='Total Number of Positive Caeses', fill='Country')+
theme(plot.title = element_text(hjust = 1, size = 22),
axis.ticks.y = element_blank(),
axis.text.y = element_blank()) +
transition_states(week)+
ease_aes("cubic-in-out")
animate(a1, nframes = 400)
df <- read.csv("all-states-history.csv")
df$week <- week(df$date)
d1 <- df %>% group_by(week, state) %>% summarise(mean = mean(hospitalizedCurrently))
d2 <- d1 %>% group_by(week) %>% mutate(rank=rank(-mean))
d3 <- d2 %>% filter(rank <= 10)
a1 <- d3 %>% ggplot(aes(x=rank, y=mean, group=state, fill=state, label=state)) + geom_col()+
geom_text(aes(y = mean, label = state), hjust = 1.4)+
coord_flip(clip = "off", expand = FALSE) +scale_x_reverse()+
labs(title = 'Week {closest_state}', x='', y='Total Number of Positive Caeses', fill='state')+
theme(plot.title = element_text(hjust = 1, size = 22),
axis.ticks.y = element_blank(),
axis.text.y = element_blank()) +
transition_states(week)+
ease_aes("cubic-in-out")
animate(a1, nframes = 400)
## Warning: Removed 27 rows containing missing values (position_stack).
## Warning: Removed 2 rows containing missing values (geom_text).
## Removed 2 rows containing missing values (geom_text).
## Removed 2 rows containing missing values (geom_text).
## Warning: Removed 8 rows containing missing values (geom_text).
## Removed 8 rows containing missing values (geom_text).
## Removed 8 rows containing missing values (geom_text).
## Removed 8 rows containing missing values (geom_text).
## Removed 8 rows containing missing values (geom_text).
## Removed 8 rows containing missing values (geom_text).
## Removed 8 rows containing missing values (geom_text).
## Removed 8 rows containing missing values (geom_text).
## Warning: Removed 10 rows containing missing values (geom_text).
## Removed 10 rows containing missing values (geom_text).
## Removed 10 rows containing missing values (geom_text).
## Removed 10 rows containing missing values (geom_text).
## Removed 10 rows containing missing values (geom_text).
## Removed 10 rows containing missing values (geom_text).
## Removed 10 rows containing missing values (geom_text).
## Removed 10 rows containing missing values (geom_text).
## Warning: Removed 9 rows containing missing values (geom_text).
## Removed 9 rows containing missing values (geom_text).
## Removed 9 rows containing missing values (geom_text).
## Removed 9 rows containing missing values (geom_text).
## Removed 9 rows containing missing values (geom_text).
## Removed 9 rows containing missing values (geom_text).
## Removed 9 rows containing missing values (geom_text).
## Removed 9 rows containing missing values (geom_text).